<?php
namespace jy_cun9bao;
defined('BY_JYA') or exit('error');
/*
	任务
*/
class task extends \plugin{
    public function jifen_sf($setting=array()){
		if($setting){
			$this->setting=$setting;
		}
        if(!$this->setting['is_open']){
            return false;
        }
		$this->model('model')->up_redfee();
		$this->model('model')->up_del_day();
        return true;
    }
	public function upoldmember(){
		$list=pdo_getall('jy_cun9fan_level',array('uniacid'=>$_SESSION['uniacid']));
		$levelids=array();
		foreach($list as $level){
			$isadd=pdo_get('jy_cun9bao_level',array('title'=>$level['title'],'uniacid'=>$_SESSION['uniacid']));
			if(!$isadd['id']){
				$data=array(
					'title'=>trim($level['title']),
					'level'=>intval($level['level']),
					'conditions'=>$level['conditions'],
					'red_rate'=>$level['red_rate'],
				);
				$data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_cun9bao_level',$data);
				$isadd['id']=pdo_insertid();
			}
			$levelids[$level['id']]=$isadd['id'];
		}
		$isup=pdo_get('jy_cun9bao_member',array('stop'=>0,'is_agent'=>1,'oldpayfee >'=>0,'uniacid'=>$_SESSION['uniacid']));
		if($isup['id']){
			return true;
		}
		$list=pdo_getall('jy_cun9fan_member',array('uniacid'=>$_SESSION['uniacid']));
		foreach($list as $member){
			$isadd=pdo_get('jy_cun9bao_member',array('mid'=>$member['mid'],'uniacid'=>$_SESSION['uniacid']));
			if(!$isadd['mid']){
				$rednum=pdo_count('jy_cun9fan_fanlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$member['mid']));
				$redfee=pdo_getsum('jy_cun9fan_fanlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$member['mid']),'lastfanfee');
				$oldpayfee=pdo_getsum('jy_cun9fan_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$member['mid']),'price');
				$oldfenfee=pdo_getsum('jy_cun9fan_commission',array('type'=>array(6,7),'uniacid'=>$_SESSION['uniacid'],'mid'=>$member['mid']),'money');
				$data=array(
					'mid'=>$member['mid'],
					'agent_id'=>$member['agent_id'],
					'createtime'=>$member['createtime'],
					'is_agent'=>$member['is_agent'],
					'stop'=>$member['stop'],
					'level_id'=>$levelids[$member['level_id']],
					'agenttime'=>$member['agenttime'],
					'updatetime'=>$member['updatetime'],
					'mobile'=>$member['mobile'],
					'realname'=>$member['realname'],
					'wechat'=>$member['wechat'],
					'lat_lng'=>$member['lat_lng'],
					'pcd'=>$member['pcd'],
					'order_time'=>$member['order_time'],
					'agent_num'=>$member['agent_num'],
					'member_num'=>$member['member_num'],
					'redfee'=>$redfee,
					'rednum'=>$rednum,
					'lastredfee'=>$redfee,
					'oldpayfee'=>$oldpayfee,
					'oldfenfee'=>$oldfenfee,
					'nocheck'=>$member['nocheck'],
				);
				$data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_cun9bao_member',$data);
			}
		}
		return '';
	}
}